
$.extend( $.fn.dataTable.defaults, {
    searching: false,
    ordering:  true,
    lengthChange:false,
    "language": {
        "emptyTable":     "无数据",
        "info":           "当前 _START_ 到 _END_ 条(共 _TOTAL_ 条)",
        "infoEmpty":      "",
        "infoFiltered":   "(filtered from _MAX_ total entries)",
        "infoPostFix":    "",
        "thousands":      ",",
        "lengthMenu":     "Show _MENU_ entries",
        "loadingRecords": "加载中...",
        "processing":     "加载中...",
        "search":         "Search:",
        "zeroRecords":    "未找到匹配的记录！",
        "paginate": {
            "first":      "首页",
            "last":       "最后",
            "next":       "下页",
            "previous":   "上页"
        },
        "aria": {
            "sortAscending":  ": activate to sort column ascending",
            "sortDescending": ": activate to sort column descending"
        }
    },
    "columnDefs": [{
  		"targets": "_all",
  		"defaultContent": ""
	}],
	"aoColumnDefs": [
	       			{
	    				sDefaultContent: '',
	    				aTargets: [ '_all' ]
	    			}
	    		]
} );

$.fn.dataTable.ext.errMode='none';


////获得table被checkbox选择行的数据，传入table的id和checkbox所在的列数（0开始）
function getSelect(tableId,num){
	   var selects=[];
	   var selecttr=tableId+" tbody tr"
	   jQuery(selecttr).each(function(){
			var isChecked = $(this).children("td").eq(num).find("input:checkbox").prop("checked");
			if(isChecked)
			{  
				var data = $(tableId).dataTable().fnGetData($(this));
				selects.push(data);
			}
		})
		return selects
}

function delSelect(selects,url,tableName){
	if(selects.length==0){
	       $.springLemonDialog({
	         content: '请选择删除的记录',// 确认文本
	         clickButton: function (sender, modal, index) {// 按钮事件处理
	             $(this).closeDialog(modal);
	         }
	       }); 
	   }else{
		   var ids=selects[0].id;
		   for(var i=1;i<selects.length;i++){
			   ids += ',' + selects[i].id;  
		   }
		   var api=url+"?ids="+ids;
		   $.springLemonDialog({
		         content: '确认删除'+selects.length+'条记录？',// 确认文本
		         clickButton: function (sender, modal, index) {// 按钮事件处理
		        	 if (index == 0) {
		        		 jQuery(".btn").attr("disabled", true);
		        		 jQuery.ajax({
		        			    url:encodeURI(api),
		        	            cache:false,
		        	            type :"get",
		        	            dataType:"json",
		        	            contentType:"application/json;charset=utf-8",//解决返回数据中的中文乱码问题
		        	            success:function(data){
		        	            	jQuery(".btn").attr("disabled", false);
		        	            	tableName.draw(false); 
		        	            }
		        	        });	
		        	 }
		             $(this).closeDialog(modal);
		         }
		       });  
	   }
	
}
/**
 * 前台使用patch的API保存日志
 */
function addOperateLog(operateType,content){
	var logUrl = window.rootPath + "/ui/log/addOperateLog";
	var logData = {
			"operateType" : operateType,
			"content" : content
	}
	jQuery.ajax({
		type : 'post',
		url : encodeURI(logUrl),
		data : logData,
		dataType : 'json',
		success : function(d) {
			
		}
	});
}

/**
 * 发生信息流转时写入流转记录
 * 
 */
function addChanceFlowNode(chanceId,startNode,endNode,flowOperate){
	var nodeUrl = window.rootPath + "/ui/chance/flow";
	var nodeData = {
			"chance" : {"id":chanceId},
			"startNode" : startNode,
			"endNode" : endNode,
			"flowOperate" : flowOperate
	}
	jQuery.ajax({
		type : 'post',
		url : encodeURI(nodeUrl),
		data : JSON.stringify(nodeData),
		dataType : 'json',
		contentType : 'application/json;charset=utf-8',
		success : function(d) {
			
		}
	});
}
////清除不是数字的字符
function clearNoNum(obj) {
	   obj.value = obj.value.replace(/[^\d.]/g,"");  //清除"数字"和"."以外的字符
	   obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
	   obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	   obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");   
}
////验证字母
function formChar(obj) {
	obj.value = obj.value.replace(/[^a-zA-Z]+$/,"");  //只能输入由26个英文字母组成的字符串
}
////清除不是整数的字符
function clearNoInteger(obj) {
	obj.value = obj.value.replace(/[^\d]/g,"");  //清除"数字"以外的字符
	obj.value = obj.value.replace(/\d{10,}/g,obj.value.substring(0,9)); //只保留九位数 清除多余的
}

//导出导出table中选中的记录
function exportSelects(selects,url){
	var ids=selects[0].id;
	   for(var i=1;i<selects.length;i++){
		   ids += ',' + selects[i].id;  
	   }
	   var api=url+"?ids="+ids;
	   
}

/////对cell的字数限制
function stringCut(source, len){
	if(source){
		if(source.length<=len){
			return source;
		}else{
			return source.substring(0,len-1)+"...";
		}
	}else{
		return '';
	}
}






